﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using Client_Web.ServiceReference;

using Service_Gallery;

namespace Client_Web
{
    public partial class AlbumList : System.Web.UI.Page
    {
        protected List<AlbumStruct> albumList;
        protected List<AlbumStruct> userAlbumList;

        protected string[] albumStringList;

        protected void Page_Load(object sender, EventArgs e)
        {
            ServiceClient serviceClient = new ServiceClient();
            String action = Request.QueryString["Action"];
            if ("delete" == action)
            {
                serviceClient.deleteAlbum(Request.QueryString["AlbumId"]);
            }

            albumStringList = serviceClient.getAlbumList();

            albumList = new List<AlbumStruct>();
            for (int i = 1; i < albumStringList.Length; i++)
            {
                string[] data = Util.CleanAndSplit(albumStringList[i]);

                AlbumStruct album = new AlbumStruct();
                album.id = data[0];
                album.name = data[1];
                album.date = data[2];
                albumList.Add(album);
            }

            if (null != Session["userIdStr"])
            {
                albumStringList = serviceClient.getUserAlbum((string)Session["userIdStr"]);
                userAlbumList = new List<AlbumStruct>();
                for (int i = 1; i < albumStringList.Length; i++)
                {
                    string[] data = Util.CleanAndSplit(albumStringList[i]);

                    AlbumStruct album = new AlbumStruct();
                    album.id = data[0];
                    album.name = data[1];
                    album.date = data[2];
                    userAlbumList.Add(album);
                }
            }
            Title = "Liste des albums";
        }
    }
}